/**
 * @Title: BaseController
 * @Package cn.com.yiqi.wsc.portal.controller.admin
 * @Description: TODO
 * Copyright: Copyright (c) 2016
 * Company: 成都壹柒互动科技有限公司
 * @author 会员系统组-胥钰淋
 * @date 2017/2/13 10:06
 * @version V1.0
 */
package cn.com.yiqi.wsc.portal.controller;

import cn.com.yiqi.wsc.entity.user.User;
import cn.com.yiqi.wsc.portal.common.DateEditor;
import cn.com.yiqi.wsc.portal.common.Message;
import cn.com.yiqi.wsc.service.user.UserService;
import cn.com.yiqi.wsc.util.JsonUtil;
import cn.com.yiqi.wsc.util.SpringUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author 会员系统组-胥钰淋
 * @ClassName: BaseController
 * @Description: TODO
 * @date 2017/2/13 10:06
 */
public class BaseController {

    @Autowired
    protected UserService userService;

    protected void getUserData (ModelAndView mv) {
        Map<String, Object> result = new HashMap<>();
        User user = userService.getCurrentUser();
        result.put("info", user);
        if (null != user) {
            String username = user.getLoginName();
            if (StringUtils.isEmpty(username)) {
                username = user.getTel();
            }
            Set<String> permissions = userService.findPermissions(username);
            result.put("permissions", permissions);
        }
        mv.addObject("user", JsonUtil.toJSON(result));
    }

}
